package com.fr.dialog.core;

import com.fr.base.DefaultValues;
import com.fr.base.FRContext;
import com.fr.base.FRFont;
import com.fr.base.Inter;
import com.fr.base.core.BaseCoreConstants;
import com.fr.base.core.GraphHelper;
import com.fr.cell.core.JNumberField;
import com.fr.cell.core.layout.LayoutFactory;
import com.fr.dialog.BasicPane;
import com.fr.util.Utils;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.EventListenerList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.text.Document;

public class FRFontPane extends BasicPane
{
  private JTextField familyField;
  private JList familyList;
  private JNumberField sizeField;
  private JList sizeList;
  private JTextField styleField;
  private JList styleList;
  private ColorSelectionPane foregroundColorPane;
  private LineComboBox underlineCombo;
  private JCheckBox isStrikethroughCheckBox;
  private JCheckBox isShadowCheckBox;
  private JCheckBox isSuperscriptCheckBox;
  private JCheckBox isSubscriptCheckBox;
  private PreivewArea preview;
  private EventListenerList eventChangeList = new EventListenerList();
  ActionListener actionListener = new ActionListener(this)
  {
    private final FRFontPane this$0;

    public void actionPerformed()
    {
      this.this$0.fireStateChanged();
    }
  };
  ChangeListener changeListener = new ChangeListener(this)
  {
    private final FRFontPane this$0;

    public void stateChanged()
    {
      this.this$0.fireStateChanged();
    }
  };
  javax.swing.event.ListSelectionListener listSelectionListener = new javax.swing.event.ListSelectionListener(this)
  {
    private final FRFontPane this$0;

    public void valueChanged()
    {
      this.this$0.fireStateChanged();
    }
  };
  DocumentListener documentListener = new DocumentListener(this)
  {
    private final FRFontPane this$0;

    public void changedUpdate()
    {
      this.this$0.fireStateChanged();
    }

    public void insertUpdate()
    {
      this.this$0.fireStateChanged();
    }

    public void removeUpdate()
    {
      this.this$0.fireStateChanged();
    }
  };

  public FRFontPane()
  {
    initComponents();
  }

  protected void initComponents()
  {
    setLayout(LayoutFactory.createBorderLayout());
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    JPanel localJPanel1 = new JPanel();
    add(localJPanel1, "North");
    localJPanel1.setLayout(new BoxLayout(localJPanel1, 1));
    JPanel localJPanel2 = new JPanel();
    localJPanel1.add(localJPanel2);
    localJPanel2.setLayout(new GridLayout(1, 2, 0, 0));
    this.familyField = new JTextField();
    this.familyField.setEditable(false);
    this.familyList = new JList(Utils.getAvailableFontFamilyNames4Report());
    this.familyList.setVisibleRowCount(4);
    this.familyList.addListSelectionListener(this.listSelectionListener);
    JPanel localJPanel3 = new JPanel();
    localJPanel2.add(localJPanel3);
    localJPanel3.setLayout(LayoutFactory.createBorderLayout());
    localJPanel3.add(createTextFieldListPane("", this.familyField, this.familyList), "Center");
    localJPanel3.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FRFont-Family")));
    JPanel localJPanel4 = new JPanel();
    localJPanel2.add(localJPanel4);
    localJPanel4.setLayout(new BoxLayout(localJPanel4, 0));
    localJPanel4.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FRFont-Style") + Inter.getLocText("FRFont-Size")));
    String[] arrayOfString = { Inter.getLocText("FRFont-plain"), Inter.getLocText("FRFont-bold"), Inter.getLocText("FRFont-italic"), Inter.getLocText("FRFont-bolditalic") };
    this.styleField = new JTextField();
    this.styleField.setEditable(false);
    this.styleList = new JList(arrayOfString);
    this.styleList.setVisibleRowCount(4);
    this.styleList.addListSelectionListener(this.listSelectionListener);
    JPanel localJPanel5 = createTextFieldListPane("", this.styleField, this.styleList);
    localJPanel4.add(localJPanel5);
    localJPanel4.add(Box.createHorizontalStrut(6));
    Integer[] arrayOfInteger = { new Integer(6), new Integer(8), new Integer(9), new Integer(10), new Integer(11), new Integer(12), new Integer(14), new Integer(16), new Integer(18), new Integer(20), new Integer(22), new Integer(24), new Integer(26), new Integer(28), new Integer(36), new Integer(48), new Integer(72) };
    this.sizeField = new JNumberField();
    JPanel localJPanel6 = createTextFieldListPane("", this.sizeField, this.sizeList = new JList(arrayOfInteger));
    this.sizeField.setMaxDecimalLength(0);
    this.sizeField.getDocument().addDocumentListener(this.documentListener);
    this.sizeField.getDocument().addDocumentListener(new DocumentListener(this)
    {
      private final FRFontPane this$0;

      public void changedUpdate()
      {
        FRFontPane.access$000(this.this$0);
      }

      public void insertUpdate()
      {
        FRFontPane.access$000(this.this$0);
      }

      public void removeUpdate()
      {
        FRFontPane.access$000(this.this$0);
      }
    });
    this.sizeList.setVisibleRowCount(4);
    this.sizeList.addListSelectionListener(this.listSelectionListener);
    localJPanel4.add(localJPanel6);
    this.styleField.setText((String)this.styleList.getSelectedValue());
    JPanel localJPanel7 = new JPanel();
    localJPanel1.add(localJPanel7);
    localJPanel7.setLayout(new GridLayout(1, 2, 0, 0));
    JPanel localJPanel8 = new JPanel();
    localJPanel7.add(localJPanel8);
    localJPanel8.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FRFont-Underline")));
    localJPanel8.setLayout(LayoutFactory.createBorderLayout());
    this.underlineCombo = new LineComboBox(BaseCoreConstants.UnderlineStyleArray);
    this.underlineCombo.addActionListener(this.actionListener);
    localJPanel8.add(this.underlineCombo, "Center");
    JPanel localJPanel9 = new JPanel();
    localJPanel7.add(localJPanel9);
    localJPanel9.setLayout(LayoutFactory.createBorderLayout());
    localJPanel9.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FRFont-Foreground")));
    this.foregroundColorPane = new ColorSelectionPane(120);
    this.foregroundColorPane.addColorChangeListener(new ChangeListener(this)
    {
      private final FRFontPane this$0;

      public void stateChanged()
      {
        this.this$0.fireStateChanged();
      }
    });
    localJPanel9.add(this.foregroundColorPane, "Center");
    JPanel localJPanel10 = new JPanel();
    add(localJPanel10, "Center");
    localJPanel10.setLayout(new BorderLayout(4, 4));
    JPanel localJPanel11 = new JPanel();
    localJPanel10.add(localJPanel11, "West");
    localJPanel11.setLayout(LayoutFactory.createBorderLayout());
    JPanel localJPanel12 = new JPanel();
    localJPanel11.add(localJPanel12, "Center");
    localJPanel12.setLayout(LayoutFactory.createBorderLayout());
    localJPanel12.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FRFont-Effects")));
    JPanel localJPanel13 = new JPanel();
    localJPanel12.add(localJPanel13, "North");
    localJPanel13.setLayout(new GridLayout(4, 1));
    this.isStrikethroughCheckBox = new JCheckBox(Inter.getLocText("FRFont-Strikethrough") + "  ");
    this.isStrikethroughCheckBox.addChangeListener(this.changeListener);
    this.isStrikethroughCheckBox.setMnemonic('K');
    this.isShadowCheckBox = new JCheckBox(Inter.getLocText("FRFont-Shadow"));
    this.isShadowCheckBox.addChangeListener(this.changeListener);
    this.isShadowCheckBox.setMnemonic('S');
    this.isSuperscriptCheckBox = new JCheckBox(Inter.getLocText("FRFont-Superscript"));
    this.isSuperscriptCheckBox.addChangeListener(this.changeListener);
    this.isSuperscriptCheckBox.setMnemonic('E');
    this.isSubscriptCheckBox = new JCheckBox(Inter.getLocText("FRFont-Subscript"));
    this.isSubscriptCheckBox.addChangeListener(this.changeListener);
    this.isSubscriptCheckBox.setMnemonic('B');
    localJPanel13.add(getLeftJustPane(this.isStrikethroughCheckBox));
    localJPanel13.add(getLeftJustPane(this.isShadowCheckBox));
    localJPanel13.add(getLeftJustPane(this.isSuperscriptCheckBox));
    localJPanel13.add(getLeftJustPane(this.isSubscriptCheckBox));
    JPanel localJPanel14 = new JPanel();
    localJPanel10.add(localJPanel14, "Center");
    localJPanel14.setLayout(LayoutFactory.createBorderLayout());
    this.preview = new PreivewArea(this);
    this.preview.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("Preview")));
    localJPanel14.add(this.preview, "Center");
    this.isSuperscriptCheckBox.addChangeListener(this.changeListener);
    this.isSuperscriptCheckBox.addChangeListener(new ChangeListener(this)
    {
      private final FRFontPane this$0;

      public void stateChanged()
      {
        if (FRFontPane.access$100(this.this$0).isSelected())
          FRFontPane.access$200(this.this$0).setSelected(false);
      }
    });
    this.isSubscriptCheckBox.addChangeListener(this.changeListener);
    this.isSubscriptCheckBox.addChangeListener(new ChangeListener(this)
    {
      private final FRFontPane this$0;

      public void stateChanged()
      {
        if (FRFontPane.access$200(this.this$0).isSelected())
          FRFontPane.access$100(this.this$0).setSelected(false);
      }
    });
    DefaultValues localDefaultValues = FRContext.getDefaultValues();
    populate(localDefaultValues.getFRFont());
  }

  public void addChangeListener(ChangeListener paramChangeListener)
  {
    this.eventChangeList.add(ChangeListener.class, paramChangeListener);
  }

  public void fireStateChanged()
  {
    Object[] arrayOfObject = this.eventChangeList.getListenerList();
    ChangeEvent localChangeEvent = null;
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == ChangeListener.class)
      {
        if (localChangeEvent == null)
          localChangeEvent = new ChangeEvent(this);
        ((ChangeListener)arrayOfObject[(i + 1)]).stateChanged(localChangeEvent);
      }
  }

  private JPanel getLeftJustPane(JComponent paramJComponent)
  {
    JPanel localJPanel = new JPanel();
    localJPanel.setLayout(LayoutFactory.createBorderLayout());
    localJPanel.add(paramJComponent, "Center");
    localJPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
    return localJPanel;
  }

  public void populate(FRFont paramFRFont)
  {
    this.familyList.setSelectedValue(paramFRFont.getName(), true);
    this.familyField.setText(paramFRFont.getName());
    this.styleList.setSelectedIndex(paramFRFont.getStyle());
    this.sizeList.setSelectedValue(new Integer(paramFRFont.getSize()), true);
    this.sizeField.setValue(paramFRFont.getSize());
    this.foregroundColorPane.setColor(paramFRFont.getForeground());
    this.underlineCombo.setSelectedLineStyle(paramFRFont.getUnderline());
    this.isStrikethroughCheckBox.setSelected(paramFRFont.isStrikethrough());
    this.isShadowCheckBox.setSelected(paramFRFont.isShadow());
    this.isSuperscriptCheckBox.setSelected(paramFRFont.isSuperscript());
    this.isSubscriptCheckBox.setSelected(paramFRFont.isSubscript());
    ListHandler localListHandler = new ListHandler(this);
    this.familyList.addListSelectionListener(localListHandler);
    this.styleList.addListSelectionListener(localListHandler);
    this.sizeList.addListSelectionListener(localListHandler);
    9 local9 = new ActionListener(this)
    {
      private final FRFontPane this$0;

      public void actionPerformed()
      {
        FRFontPane.access$000(this.this$0);
      }
    };
    this.isStrikethroughCheckBox.addActionListener(local9);
    this.isShadowCheckBox.addActionListener(local9);
    this.isSuperscriptCheckBox.addActionListener(local9);
    this.isSubscriptCheckBox.addActionListener(local9);
    this.underlineCombo.addItemListener(new ItemListener(this)
    {
      private final FRFontPane this$0;

      public void itemStateChanged()
      {
        FRFontPane.access$000(this.this$0);
      }
    });
    this.foregroundColorPane.addColorChangeListener(new ChangeListener(this)
    {
      private final FRFontPane this$0;

      public void stateChanged()
      {
        FRFontPane.access$000(this.this$0);
      }
    });
    updatePreviewLabel();
  }

  public FRFont update()
  {
    return FRFont.getInstance(this.familyField.getText(), this.styleList.getSelectedIndex(), (int)this.sizeField.getValue(), this.foregroundColorPane.getColor(), this.underlineCombo.getSelectedLineStyle(), this.isStrikethroughCheckBox.isSelected(), this.isShadowCheckBox.isSelected(), this.isSuperscriptCheckBox.isSelected(), this.isSubscriptCheckBox.isSelected());
  }

  private JPanel createTextFieldListPane(String paramString, JTextField paramJTextField, JList paramJList)
  {
    GridBagLayout localGridBagLayout = new GridBagLayout();
    JPanel localJPanel = new JPanel(localGridBagLayout);
    GridBagConstraints localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = (localGridBagConstraints.gridy = 0);
    localGridBagConstraints.gridwidth = (localGridBagConstraints.gridheight = 1);
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    JLabel localJLabel = new JLabel(paramString);
    localGridBagLayout.setConstraints(localJLabel, localGridBagConstraints);
    localJPanel.add(localJLabel);
    localGridBagConstraints.gridy = 1;
    Component localComponent = Box.createVerticalStrut(0);
    localGridBagLayout.setConstraints(localComponent, localGridBagConstraints);
    localJPanel.add(localComponent);
    localGridBagConstraints.gridy = 2;
    localGridBagLayout.setConstraints(paramJTextField, localGridBagConstraints);
    localJPanel.add(paramJTextField);
    localGridBagConstraints.gridy = 3;
    localComponent = Box.createVerticalStrut(2);
    localGridBagLayout.setConstraints(localComponent, localGridBagConstraints);
    localJPanel.add(localComponent);
    localGridBagConstraints.gridy = 4;
    localGridBagConstraints.gridheight = 0;
    localGridBagConstraints.weighty = 1.0D;
    JScrollPane localJScrollPane = new JScrollPane(paramJList);
    localGridBagLayout.setConstraints(localJScrollPane, localGridBagConstraints);
    localJPanel.add(localJScrollPane);
    return localJPanel;
  }

  private void updatePreviewLabel()
  {
    this.preview.setPaintFont(update());
  }

  static void access$000(FRFontPane paramFRFontPane)
  {
    paramFRFontPane.updatePreviewLabel();
  }

  static JCheckBox access$100(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.isSuperscriptCheckBox;
  }

  static JCheckBox access$200(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.isSubscriptCheckBox;
  }

  static JList access$300(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.familyList;
  }

  static JTextField access$400(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.familyField;
  }

  static JList access$500(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.sizeList;
  }

  static JNumberField access$600(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.sizeField;
  }

  static JList access$700(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.styleList;
  }

  static JTextField access$800(FRFontPane paramFRFontPane)
  {
    return paramFRFontPane.styleField;
  }

  class PreivewArea extends JComponent
  {
    private String paintText;
    private FRFont paintFont;
    private final FRFontPane this$0;

    public PreivewArea()
    {
      this.this$0 = paramFRFontPane;
      this.paintText = "Report";
      this.paintFont = null;
      this.paintFont = FRContext.getDefaultValues().getFRFont();
    }

    public void setPaintFont()
    {
      this.paintFont = paramFRFont;
      repaint();
    }

    public void paintComponent()
    {
      Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
      Dimension localDimension = getSize();
      localGraphics2D.setColor(getBackground());
      GraphHelper.fillRect(localGraphics2D, 0.0D, 0.0D, localDimension.width, localDimension.height);
      if (this.paintFont == null)
        return;
      FontMetrics localFontMetrics = getFontMetrics(this.paintFont);
      localGraphics2D.setColor(this.paintFont.getForeground());
      localGraphics2D.setFont(this.paintFont);
      int i = (localDimension.width - localFontMetrics.stringWidth(this.paintText)) / 2;
      int j = (localDimension.width + localFontMetrics.stringWidth(this.paintText)) / 2;
      int k = (localDimension.height - localFontMetrics.getHeight()) / 2 + localFontMetrics.getAscent();
      GraphHelper.drawLine(localGraphics2D, 4.0D, k, i - 8, k, 1);
      GraphHelper.drawString(localGraphics2D, this.paintText, i, k);
      GraphHelper.drawLine(localGraphics2D, j + 8, k, localDimension.width - 4, k, 1);
    }
  }

  class ListHandler
    implements javax.swing.event.ListSelectionListener
  {
    private final FRFontPane this$0;

    ListHandler()
    {
      this.this$0 = paramFRFontPane;
    }

    public void valueChanged()
    {
      Object localObject2;
      Object localObject1 = paramListSelectionEvent.getSource();
      if (localObject1 == FRFontPane.access$300(this.this$0))
      {
        localObject2 = (String)FRFontPane.access$300(this.this$0).getSelectedValue();
        if (localObject2 != null)
          FRFontPane.access$400(this.this$0).setText((String)localObject2);
      }
      else if (localObject1 == FRFontPane.access$500(this.this$0))
      {
        localObject2 = (Integer)FRFontPane.access$500(this.this$0).getSelectedValue();
        if (localObject2 != null)
          FRFontPane.access$600(this.this$0).setValue(((Integer)localObject2).intValue());
      }
      else if (localObject1 == FRFontPane.access$700(this.this$0))
      {
        localObject2 = (String)FRFontPane.access$700(this.this$0).getSelectedValue();
        if (localObject2 != null)
          FRFontPane.access$800(this.this$0).setText((String)localObject2);
      }
      FRFontPane.access$000(this.this$0);
    }
  }
}